<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime : 2020-01-07 13:30:10
 * @LastEditors  : Please set LastEditors
 -->
<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>Hello APP</title>
	<link rel="stylesheet" type="text/css" href="../css/vant.css">
	<link rel="stylesheet" type="text/css" href="../css/base.css" />
	<script type="text/javascript" src="../script/jquery.js"></script>
	<script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
	<script type="text/javascript" src="../script/vue.min.js"></script>
	<script type="text/javascript" src="../script/vant.min.js"></script>
	<script type="text/javascript" src="../script/fastclick.js"></script>
	<script type="text/javascript" src="../script/base.js"></script>
	<script type="text/javascript" src="../script/db.js"></script>
	<style type="text/css">
		.main-animate {
			height: 232px;
			overflow: hidden;
			transition: all .4s;
		}

		.toggle-1 {
			text-align: center;
			padding: 10px 0;
		}

		.toggle-1 img {
			width: 20px;
			transition: all .4s;
		}

		.toggle-1 img.rotate {
			transform: rotate(180deg);
		}

		.p-select {
			padding: 0 30px 15px;
		}

		.p-select span,
		.p-select i {
			vertical-align: middle;
		}

		.item .van-field__label {
			width: 60%;
			max-width: inherit;
		}

		.item .van-field__control {
			text-align: right;
		}

		.delete {
			width: 16px;
			height: 16px;
		}

		.delete img {
			width: 16px;
			vertical-align: text-top;
		}

		.hide {
			height: 0;
		}

		.shadow {
			box-shadow: 0 0 5px rgb(200, 198, 198);
			position: relative;
			background: #fff;
		}

		.font-danger .van-stepper__input {
			color: #cd1b21;
		}

		.sq {
			display: inline-block;
			width: 4px;
			height: 14px;
			background: #cd1b21;
			vertical-align: text-bottom;
			left: -15px;
			position: relative;
			box-shadow: 1px 0px 3px 0 #cd1b21;
		}

		.NotifyClass {
			padding-top: 40px;
			font-size: 16px;
			font-weight: 600;
		}
	</style>
</head>

<body>
	<div id="app" v-cloak>
		<div class="init-full" @click="clickDom($event)">
			<van-nav-bar class="head" title="收款单" left-arrow @click-left="onClickLeft">

				<div slot="right" class="head-right">
					<span @click.stop="showMenu = !showMenu">
						<img src="../image/menu.png" />
					</span>
				</div>

			</van-nav-bar>
			<div class="body-with-bottom">
				<div class="content content-padding">

					<div style="padding: 0 10px 15px;">
						<div class="shadow">
							<div class="content-label">基本信息</div>
							<div>
								<van-cell :value="formData.ClientName" is-link @click="openScreen(-1,10)">
									<div slot="title">
										<span class="sq"></span>
										<span style="margin-left:-8px;">往来单位</span>
									</div>
								</van-cell>
								<van-cell title="应收账款" :value="formData.AXMoney"></van-cell>
								<van-cell title="预收账款" :value="formData.YXMoney"></van-cell>
								<van-field style="display: none;"></van-field>
							</div>
							<div class="main-animate" :class="!showMain?'hide':''">
								<van-field label="抹零金额" type="number" v-model="formData.PerMoney"></van-field>
								<van-cell title="分支机构" :value="formData.BranchName" is-link @click="openScreen(-1,99)">
								</van-cell>
								<van-cell title="经手人" :value="formData.EmplName" is-link @click="openScreen(-1,21)">
								</van-cell>
								<van-cell title="部门" :value="formData.ClassName" is-link @click="openScreen(-1,20)">
								</van-cell>
								<van-field label="备注" v-model="formData.Explain"></van-field>
							</div>

							<div class="toggle-1" @click="toggleShowMain">
								<img src="../image/retract.png" :class="!showMain?'rotate':''" />
							</div>

						</div>
					</div>

					<div class="p-select" v-if="type != 3">

						<van-row gutter="30">
							<van-col span="6"></van-col>
							<van-col span="12">
								<van-button type="primary" block size="small" @click="openScreen(-1,40)">
									<van-icon name="gold-coin-o"></van-icon>
									<span>收款账户</span>
								</van-button>
							</van-col>
							<van-col span="6"></van-col>
						</van-row>
					</div>
					<div style="padding: 0 10px 15px;">
						<div class="shadow">
							<div class="content-label">账户明细</div>
							<div class="no-data" v-show="!formDetailData.length">暂无数据</div>
							<div class="item">
								<van-field v-model="row.price" type="number" v-for="(row,index) in formDetailData"
									v-on:input="changeStepper(row)" :id="'price_' + index" @click="focusInput(index)"
									placeholder="请输入收款金额">
									<div slot="label">
										<span class="delete" @click="deleteRow(row,index)"><img
												src="../image/delete.png" /></span>
										{{row.name}}
									</div>
								</van-field>
							</div>
						</div>
					</div>
					<img class="seal" :src="getSealImage()" v-if="sealType!=0" />
				</div>
				<van-loading v-if="showLoading" />
			</div>
			<div class="bottom">
				<div class="bottom-left-label_">
					<span>合计:</span>
					<span class="number">￥{{getTotalPrice()}}</span>
				</div>
				<!-- <div class="bottom-right-button">
					<van-button :disabled="ifConfirm || type == 3" :loading="ifConfirm" loading-text="数据提交中..."
						type="primary" block @click="submitForm">{{type == 3?'已过账':'提交'}}</van-button>
				</div> -->
				<div class="bottom-right-button_">
					<div class="rad"
						style="display: flex;align-items: center;justify-content: flex-end;padding-right: 10px;">
						<van-button class="b-color-1" style="border-radius:15px;width: 100px;"
							:disabled="ifConfirm || type == 3" :loading="ifConfirm" loading-text="数据提交中..."
							type="primary" @click="isPaySubmit = false;submitForm()">{{type == 3?'已过账':'提交'}}
						</van-button>
						<!-- <van-button class="b-color-2" style="border-radius:0 15px 15px 0;"
							:disabled="ifConfirm || isPay == 1" type="primary" @click="payForm">{{payText}}
						</van-button> -->

					</div>

				</div>
			</div>
		</div>

		<div class="head-menu" v-if="showMenu">
			<img class="menu-arrow" src="../image/menu-arrow.png" />

			<div @click="openHistory" v-show="type == 0">
				<img src="../image/history.png" />
				<span>历史单据</span>
			</div>
			<div @click="openDraft">
				<img src="../image/draft-list.png" />
				<span>历史草稿</span>
			</div>
			<div @click="saveLocal" v-show="type == 0">
				<img src="../image/draft.png" />
				<span>保存草稿</span>
			</div>
			<div @click="openPosting" v-if="formID && type != 3">
				<img src="../image/3.png" />
				<span>审核过账</span>
			</div>
		</div>
	</div>
</body>

<script type="text/javascript">
	var vm;
	apiready = function () {
		//$('.init-full').show();

		api.addEventListener({
			name: 'keyback'
		}, function (ret, err) {
			vm.onClickLeft();
		});

		api.addEventListener({
			name: 'reloadForm'
		}, function (ret, err) {
			if (historyData) {
				var obj = {
					S_Type: 9,
					S_BillType: 401,
					S_BillID: vm.formID
				}
				FLD.ajax('AP_WLPayZTCL', obj, function (res) {
					vm.type = res.ds[0].B_Type;
					vm.isPay = res.ds[0].IsPayN;
					vm.payText = res.ds[0].AR_ZT;
					vm.sealType = res.ds[0].IsPayZT;
				})
			}
		})

		api.addEventListener({
			name: 'selectArray'
		}, function (ret, err) {
			var selectType = ret.value.selectType;
			var type = ret.value.type;
			var array = ret.value.array;
			if (selectType == 40) {
				var newArray = [];
				for (var i in array) {
					var row = array[i];
					var x = 0;
					for (var j in vm.formDetailData) {
						if (row.id == vm.formDetailData[j].id) {
							x = 1;
							vm.formDetailData[j].price = row.price || 0;
						}
					}
					if (x == 0) {
						newArray.push({
							hasEdit: false,
							id: row.id,
							detailID: 0,
							name: row.name,
							code: row.code,
							price: row.price || 0
						})
					}


				}
				vm.formDetailData = newArray.concat(vm.formDetailData);
			}
		})

		api.addEventListener({
			name: 'selectRow'
		}, function (ret, err) {
			var selectType = ret.value.selectType;
			var type = ret.value.type;
			var row = ret.value.row;
			if (selectType == 10) {
				vm.formData.ClientName = row.name;
				vm.formData.ClientID = row.id;
				vm.formData.AXMoney = row.AXMoney;
				vm.formData.YXMoney = row.YXMoney;

				if (vm.formDetailData.length == 1) {
					vm.formDetailData[0].price = row.AXMoney;
				}

				if (!vm.formData.EmplName) {
					vm.formData.EmplName = row.S_EmplName;
					vm.formData.EmplID = row.S_EmplID;
				}
				if (!vm.formData.ClassName) {
					vm.formData.ClassName = row.S_ClassName;
					vm.formData.ClassID = row.S_ClassID;
				}
			}
			if (selectType == 21) {
				vm.formData.EmplName = row.name;
				vm.formData.EmplID = row.id;
				vm.formData.ClassName = row.S_ClassName;
				vm.formData.ClassID = row.S_ClassID;
			}
			if (selectType == 20) {
				vm.formData.ClassName = row.name;
				vm.formData.ClassID = row.id;
			}
			if (selectType == 99) {
				vm.formData.BranchName = row.name;
				vm.formData.BranchID = row.id;

			}

		});

		var historyData = api.pageParam.historyData;
		var draftID = api.pageParam.draftID;
		var userInfo = FLD.getUserInfo();
		vm = new Vue({
			el: '#app',
			data: {
				showLoading: false,
				showMain: false,
				ifConfirm: false,
				showMenu: false,
				type: 0,
				formID: 0,
				isPay: 0,
				payText: '支付',
				sealType: 0,
				isPaySubmit: false,
				formData: {
					ClientID: 0,
					ClientName: '',
					AXMoney: '',
					YXMoney: '',
					PerMoney: '',
					BranchID: userInfo.S_BranchID,
					BranchName: userInfo.S_BranchName,
					EmplID: userInfo.S_EmplID,
					EmplName: userInfo.S_EmplName,
					ClassID: userInfo.S_ClassID,
					ClassName: userInfo.S_ClassName,
					Explain: ''
				},
				formDetailData: [],
				deleteFormDetailData: []
			},
			created: function () {
				var that = this;
				if (historyData) {
					that.type = historyData.B_Type;
					that.isPay = historyData.IsPayN;
					that.formID = historyData.BillID;
					that.payText = historyData.AR_ZT;
					that.sealType = historyData.IsPayZT;
					that.formData = {
						ClientID: historyData.ClientID || 0,
						ClientName: historyData.ClientName || '',
						AXMoney: historyData.YSFMoney || 0,
						YXMoney: historyData.WSFMoney || 0,
						PerMoney: historyData.PerMoney || '',
						BranchID: historyData.BranchID || 0,
						BranchName: historyData.BranchName || '',
						EmplID: historyData.EmplID || 0,
						EmplName: historyData.EmplName || '',
						ClassID: historyData.ClassID || 0,
						ClassName: historyData.ClassName || '',
						Explain: historyData.Explain || ''
					}
					that.getDetailData();

				} else {
					if (draftID) {
						var sql = "select * from Draft where DraftID='" + draftID + "'";
						DB.selectSql(sql, function (data) {
							that.formData = JSON.parse(data[0].JSONStr1);
							that.formDetailData = JSON.parse(data[0].JSONStr2);
						})
					} else {
						var obj = {
							S_Type: 40,
							S_Cont: '',
							S_BranchID: this.formData.BranchID,
							S_SXZ: '',
							S_StockID: this.formData.S_StockID,
							S_CargoID: this.formData.S_CargoID,
							S_BarCode: '',
							S_PriceN: 0,
							S_ProductID: 0
						}
						FLD.ajax('AP_BasList', obj, function (res) {
							for (var i in res.ds) {
								if (res.ds[i].id == userInfo.S_ProjectID) {
									that.formDetailData = [{
										hasEdit: false,
										id: res.ds[i].id,
										detailID: 0,
										name: res.ds[i].name,
										code: res.ds[i].code,
										price: ''
									}];
								}
							}

						})
					}

				}

			},
			methods: {
				clickDom(e) {
					if (!$(e.target).closest('.head-menu').length) {
						this.showMenu = false;
					}
				},
				getSealImage() {
					var that = this;
					if (that.sealType == 1) {
						return '../image/confirmed.png';
					}
					if (that.sealType == 2) {
						return '../image/paying.png';
					}
					if (that.sealType == 3) {
						return '../image/payed.png';
					}
				},
				getDetailData() {
					var that = this;
					var obj = {
						S_BillType: 401,
						S_B_Type: that.type,
						S_BillID: that.formID
					}
					that.showLoading = true;
					FLD.ajax('AP_HisListDe_A', obj, function (res) {
						that.showLoading = false;
						if (res.ds[0].status && res.ds[0].status == 500) {
							layer.open({
								content: res.ds[0].msg,
								skin: 'msg',
								time: 2
							});
						} else {
							for (var i in res.ds) {
								var row = res.ds[i];
								that.formDetailData.push({
									hasEdit: false,
									id: row.ProjectID,
									detailID: row.BillDeID,
									name: row.ProjectName,
									code: row.ProjectCode,
									price: row.DMoney || 0
								})
							}
						}
					})
				},
				focusInput(index) {
					$('#price_' + index).focus().select();
					try {
						$('#price_' + index)[0].selectionStart = 0;
						$('#price_' + index)[0].selectionEnd = $('#price_' + index).val().length;
					} catch (e) {

					}


				},
				changeStepper(row) {
					row.hasEdit = true;
				},
				openScreen(type, index) {
					var obj = {
						S_Type: index,
						S_Cont: '',
						S_BranchID: this.formData.BranchID,
						S_SXZ: '',
						S_StockID: this.formData.S_StockID,
						S_CargoID: this.formData.S_CargoID,
						S_BarCode: '',
						S_PriceN: 0,
						S_ProductID: 0
					}

					if (index == 40) {
						api.openWin({
							name: '筛选' + index,
							url: 'common/accountScreen.html',
							reload: true,
							slidBackEnabled: false,
							pageParam: {
								filterData: obj,
								type: type
							}
						})
					} else {
						api.openWin({
							name: '筛选' + index,
							url: 'common/baseScreen.html',
							reload: true,
							slidBackEnabled: false,
							pageParam: {
								filterData: obj,
								type: type,
								allowClear: false
							}
						})
					}

				},

				deleteRow(row, index) {
					this.$dialog.confirm({
						title: '提示',
						message: '是否删除该账户?'
					}).then(() => {
						if (row.detailID != 0) {
							this.deleteFormDetailData.push(row);
						}
						this.formDetailData.splice(index, 1);


					}).catch(() => {

					});

				},
				submitForm() {
					var that = this;

					if (!that.formData.ClientID) {
						layer.open({
							content: '请选择往来单位',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					if (that.formDetailData.length == 0) {
						layer.open({
							content: '请选择收款账户',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					var x = 0;
					for (var i in that.formDetailData) {
						if (!that.formDetailData[i].price) {
							x = 1;
						}
					}
					if (x == 1) {
						layer.open({
							content: '存在收款账户金额格式不正确!',
							skin: 'msg',
							time: 2
						});
						return false;
					}


					var m = 0;
					// var m1 = userInfo.S_MaxPerMoney;
					// var m2 = that.getTotalPrice() * userInfo.S_MaxPerMBL;
					// if (m1 > m2) {
					// 	m = m1;
					// } else {
					// 	m = m2;
					// } 
					m = that.formData.PerMoney ? that.formData.PerMoney : 0;	//modified by fy 2022.4.12 抹零取消限制，可随意抹零

					if (historyData) {
						that.$dialog.confirm({
							title: '提示',
							closeOnClickOverlay: true,
							message: '是否确认提交?'
						}).then(() => {
							that.submitSQL();
						}).catch(() => {

						});
					} else {
						//modified by fy 2022.4.12 抹零取消限制，可随意抹零
						that.$dialog.confirm({
							title: '提示',
							closeOnClickOverlay: true,
							message: '是否确认提交?'
						}).then(() => {
							that.formData.PerMoney = m;
							that.submitSQL();
						}).catch(() => {

						});

						// if (m == 0) {

						// 	that.$dialog.confirm({
						// 		title: '提示',
						// 		closeOnClickOverlay: true,
						// 		message: '当前抹零上限为零,是否确认提交?'
						// 	}).then(() => {
						// 		that.formData.PerMoney = 0;
						// 		that.submitSQL();
						// 	}).catch(() => {

						// 	});
						// } else {

						// 	if (!that.formData.PerMoney) {
						// 		that.$dialog.confirm({
						// 			title: '提示',
						// 			closeOnClickOverlay: true,
						// 			message: '当前未收款' + (that.formData.AXMoney - that.getTotalPrice()) + '元,可用抹零上限为' + m + '元,是否抹零?',
						// 			cancelButtonText: '不抹零',
						// 			confirmButtonText: '抹零',
						// 			beforeClose: function (action, done) {
						// 				if (action == 'overlay') {
						// 					done();
						// 				} else if (action == 'confirm') {
						// 					done();
						// 					that.formData.PerMoney = m;
						// 					that.submitSQL();
						// 				} else if (action == 'cancel') {
						// 					done();
						// 					that.formData.PerMoney = 0;
						// 					that.submitSQL();
						// 				}
						// 			}
						// 		})

						// 	} else {
						// 		if (m > that.formData.PerMoney) {
						// 			that.$dialog.confirm({
						// 				title: '提示',
						// 				closeOnClickOverlay: true,
						// 				message: '是否确认提交?'
						// 			}).then(() => {
						// 				that.submitSQL();
						// 			}).catch(() => {

						// 			});
						// 		} else {
						// 			that.$dialog.confirm({
						// 				title: '提示',
						// 				closeOnClickOverlay: true,
						// 				message: '当前抹零上限为' + m + '元,是否确认提交?'
						// 			}).then(() => {
						// 				that.formData.PerMoney = m;
						// 				that.submitSQL();
						// 			}).catch(() => {

						// 			});
						// 		}
						// 	}


						// }
					}





				},
				submitSQL() {
					var that = this;
					if (that.type == 0) {
						var S_STRZB = [];
						for (var i in that.formData) {
							if (i == 'AXMoney' || i == 'YXMoney' || i == 'PerMoney') {
								S_STRZB.push('\'' + (that.formData[i] || 0) + '\'');
							} else {
								S_STRZB.push('\'' + that.formData[i] + '\'');
							}

						}
						var S_STRDe = [];
						for (var i in that.formDetailData) {
							var detailArray = [];
							detailArray.push(
								'\'' + that.formDetailData[i].id + '\'',
								'\'' + that.formDetailData[i].name + '\'',
								'\'' + that.formDetailData[i].code + '\'',
								'\'' + that.formDetailData[i].price + '\''
							)
							S_STRDe.push(detailArray.join(','))
						}

						var obj = {
							S_BillType: 401,
							S_STRZB: S_STRZB.join(),
							S_STRDe: S_STRDe.join('|')
						}
						that.ifConfirm = true;
						FLD.ajax('AP_XSCKTJ', obj, function (res) {
							that.ifConfirm = false;
							if (res.ds[0].status == 200) {

								//本地数据库删除草稿
								if (draftID) {
									var sql = "delete from Draft where DraftID='" + draftID + "'";
									DB.executeSql(sql, function () {
										api.sendEvent({
											name: 'refreshDraft'
										});
									})
								}

								if (that.isPaySubmit) {
									that.isPaySubmit = false;
									var payMoney = that.getTotalPrice();
									layer.open({
										content: '保存成功,即将跳转支付!',
										skin: 'msg',
										time: 2,
										end: function () {
											api.openWin({
												name: 'pay',
												url: 'common/pay.html',
												reload: true,
												slidBackEnabled: false,
												pageParam: {
													payData: {
														S_BillType: 401,
														S_BillID: res.ds[0].BillID,
														S_UserType: 1,
														S_DMoney: payMoney,
														S_BranchID: that.formData.BranchID,
														S_ClientID: that.formData.ClientID,
														S_PayType: '0'
													},
													payType: 1
												}
											})
										}
									});
								} else {
									layer.open({
										content: '保存成功',
										skin: 'msg',
										time: 2
									});
								}

								that.formData = {
									ClientID: 0,
									ClientName: '',
									AXMoney: '',
									YXMoney: '',
									PerMoney: '',
									BranchID: userInfo.S_BranchID,
									BranchName: userInfo.S_BranchName,
									EmplID: userInfo.S_EmplID,
									EmplName: userInfo.S_EmplName,
									ClassID: userInfo.S_ClassID,
									ClassName: userInfo.S_ClassName,
									Explain: ''
								}
								that.formDetailData = [];

							} else {
								layer.open({
									content: res.ds[0].msg,
									skin: 'msg',
									time: 2
								});
							}
						})
					} else {
						var S_STRZB = [2, that.type, that.formID];
						for (var i in that.formData) {
							if (i == 'AXMoney' || i == 'YXMoney' || i == 'PerMoney') {
								S_STRZB.push('\'' + (that.formData[i] || 0) + '\'');
							} else {
								S_STRZB.push('\'' + that.formData[i] + '\'');
							}

						}
						var S_STRDe = [];
						for (var i in that.formDetailData) {
							var detailArray = [];
							detailArray.push(
								'\'' + (that.formDetailData[i].detailID == 0 ? 1 : (that.formDetailData[i].hasEdit ? 2 : 0)) + '\'',
								'\'' + that.type + '\'',
								'\'' + that.formID + '\'',
								'\'' + that.formDetailData[i].detailID + '\'',
								'\'' + that.formDetailData[i].id + '\'',
								'\'' + that.formDetailData[i].name + '\'',
								'\'' + that.formDetailData[i].code + '\'',
								'\'' + that.formDetailData[i].price + '\''
							)
							S_STRDe.push(detailArray.join(','))
						}
						for (var i in that.deleteFormDetailData) {
							var detailArray = [];
							detailArray.push(
								'\'' + 3 + '\'',
								'\'' + that.type + '\'',
								'\'' + that.formID + '\'',
								'\'' + that.deleteFormDetailData[i].detailID + '\'',
								'\'' + that.deleteFormDetailData[i].id + '\'',
								'\'' + that.deleteFormDetailData[i].name + '\'',
								'\'' + that.deleteFormDetailData[i].code + '\'',
								'\'' + that.deleteFormDetailData[i].price + '\''
							)
							S_STRDe.push(detailArray.join(','));
						}
						var obj = {
							S_BillType: 401,
							S_STRZB: S_STRZB.join(),
							S_STRDe: S_STRDe.join('|')
						}
						that.ifConfirm = true;
						FLD.ajax('AP_MdfXSCKTJ', obj, function (res) {
							that.ifConfirm = false;
							if (res.ds[0].status == 200) {

								if (that.isPaySubmit) {
									that.isPaySubmit = false;
									var payMoney = that.getTotalPrice();
									layer.open({
										content: '即将跳转支付',
										skin: 'msg',
										time: 2,
										end: function () {
											api.openWin({
												name: 'pay',
												url: 'common/pay.html',
												reload: true,
												slidBackEnabled: false,
												pageParam: {
													payData: {
														S_BillType: 401,
														S_BillID: that.formID,
														S_UserType: 1,
														S_DMoney: payMoney,
														S_BranchID: that.formData.BranchID,
														S_ClientID: that.formData.ClientID,
														S_PayType: '0'
													},
													payType: 1
												}
											})
										}
									});
								} else {
									layer.open({
										content: '修改成功',
										skin: 'msg',
										time: 2
									});
								}


								that.formDetailData = [];
								that.deleteFormDetailData = [];
								api.sendEvent({
									name: 'refreshList',
									extra: {
										type: that.type
									}
								});
								that.getDetailData();
							} else {
								layer.open({
									content: res.ds[0].msg,
									skin: 'msg',
									time: 2
								});
							}
						})
					}
				},
				payForm() {
					var that = this;
					if (that.getTotalPrice() <= 0) {
						layer.open({
							content: '当前金额不允许支付!',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					that.isPaySubmit = true;
					that.submitForm();
				},
				openDraft() {
					api.openWin({
						name: 'draft',
						url: 'draft.html',
						reload: true,
						slidBackEnabled: false,
						pageParam: {
							tabActive: 1
						}
					})
				},
				saveLocal() {
					var that = this;
					that.showMenu = false;
					var jsonstr1 = JSON.stringify(that.formData).replace(/\'/g, '\'\'')
					var jsonstr2 = JSON.stringify(that.formDetailData).replace(/\'/g, '\'\'')
					if (draftID) {
						var sql = "update Draft set JSONStr1='" + jsonstr1 + "',JSONStr2='" + jsonstr2 + "',UpdateTime='" + FLD.getFormatDate() + "' where DraftID='" + draftID + "'";
						DB.executeSql(sql, function () {
							layer.open({
								content: '保存成功',
								skin: 'msg',
								time: 2
							});
							api.sendEvent({
								name: 'refreshDraft'
							});
						})
					} else {
						var sql = "insert into Draft (JSONStr1,JSONStr2,CreateTime,UpdateTime,Type,Status) values ('" + jsonstr1 + "','" + jsonstr2 + "','" + FLD.getFormatDate() + "',null,401,null)"
						DB.executeSql(sql, function () {
							layer.open({
								content: '保存成功',
								skin: 'msg',
								time: 2
							});
						})
					}

				},
				openPosting() { // 审核过账
					let that = this;

					vant.Dialog.confirm({
						title: '审核过账',
						message: '是否审核过账',
					}).then(() => {
						FLD.ajax('app_FI_CapitalApproval', {
							BillType: 401,
							KeyID: that.formID,
						}, function (res) {
							that.showLoading = false;
							if (res.ds[0].status && res.ds[0].status == 500) {
								layer.open({
									content: res.ds[0].msg,
									skin: 'msg',
									time: 2
								});
							} else {

								vant.Notify({
									message: '已过帐',
									color: '#fff',
									background: '#07c160',
									className: 'NotifyClass',
								});

								api.sendEvent({
									name: 'refreshList',
									extra: {
										type: 2
									}
								});
								api.sendEvent({
									name: 'refreshList',
									extra: {
										type: 3
									}
								});
								// 状态改为已过帐
								that.type = 3;
							}
						})
					}).catch(() => {

					});

				},

				getTotalCount() {
					var totalCount = 0;
					for (var i in this.formDetailData) {
						totalCount += this.formDetailData[i].num
					}
					return totalCount;
				},
				getTotalPrice() {
					var totalPrice = 0;
					for (var i in this.formDetailData) {
						if (this.formDetailData[i].price) {
							totalPrice += parseFloat(this.formDetailData[i].price);
						}

					}
					return totalPrice.toFixed(2);
				},
				toggleShowMain() {
					this.showMain = !this.showMain;
				},
				toggleShowDetail(row) {
					row.showDetail = !row.showDetail;
				},

				openHistory() {
					api.openWin({
						name: '历史单据',
						url: 'common/historicalDocuments.html',
						reload: true,
						slidBackEnabled: false,
						pageParam: {
							type: 401
						}
					})
				},
				onClickLeft() {
					if (this.type == 3) {
						api.closeWin();
					} else {
						this.$dialog.confirm({
							title: '提示',
							message: '是否退出收款单界面?'
						}).then(() => {
							api.closeWin();
						}).catch(() => {

						});
					}

				}
			}
		})
	};
</script>

</html>